﻿using System;
using System.IO;
class ConcatenatingTextFiles
{
    static void Main()
    {
        StreamReader reader1 = new StreamReader("../../test1.txt");
        StreamWriter writer = new StreamWriter("../../test3.txt");
        using (reader1)
        {
            int writeLine = 1;
            string line = String.Empty;
            using (writer)
            {
                while (line != null)
                {
                    try
                    {
                        line = reader1.ReadLine();

                        writer.WriteLine(line);
                    }

                    catch (ArgumentNullException)
                    {
                        Console.Write("file is empty");
                        reader1.Close();
                    }
                    catch (IOException)
                    {
                        Console.WriteLine("file is not reachable");
                        reader1.Close();
                    }
                    writeLine++;
                }
            }
        }
        Console.WriteLine("file 1 saved");
        StreamReader reader2 = new StreamReader("../../test2.txt");
        StreamWriter writer1 = new StreamWriter("../../test3.txt", true);
        using (reader2)
        {
            string line = String.Empty;
            using (writer1)
            {
                while (line != null)
                {
                    try
                    {
                        line = reader2.ReadLine();
                        writer1.WriteLine(line);
                    }
                    catch (ArgumentNullException)
                    {
                        Console.WriteLine("file is empty");
                        reader1.Close();
                    }
                    catch (IOException)
                    {
                        Console.WriteLine("file is not reachable");
                        reader1.Close();
                    }
                }
            }
        }
        reader1.Close();
        Console.WriteLine("file 2 saved");
        Console.ReadLine();
    }
}

